home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / rogue / use.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-05-13  |  11.3 KB  |  573 lines

  1. /*
  2.  * use.c
  3.  *
  4.  * This source herein may be modified and/or distributed by anybody who
  5.  * so desires, with the following restrictions:
  6.  *    1.)  No portion of this notice shall be removed.
  7.  *    2.)  Credit shall not be taken for the creation of this source.
  8.  *    3.)  This code is not to be traded, sold, or used for personal
  9.  *         gain or profit.
  10.  *
  11.  */
  12.  
  13. #ifndef CURSES
  14. #include <curses.h>
  15. #endif CURSES
  16. #include "rogue.h"
  17.  
  18. short halluc = 0;
  19. short blind = 0;
  20. short confused = 0;
  21. short levitate = 0;
  22. short haste_self = 0;
  23. boolean see_invisible = 0;
  24. short extra_hp = 0;
  25. boolean detect_monster = 0;
  26. char *strange_feeling = "you have a strange feeling for a moment, then it passes";
  27.  
  28. extern short bear_trap;
  29. extern char hunger_str[];
  30. extern short cur_room;
  31. extern long level_points[];
  32. extern boolean being_held;
  33. extern char *fruit, *you_can_move_again;
  34. extern boolean sustain_strength;
  35.  
  36. quaff()
  37. {
  38.     short ch;
  39.     char buf[80];
  40.     object *obj;
  41.  
  42.     ch = pack_letter("quaff what?", POTION);
  43.  
  44.     if (ch == CANCEL) {
  45.         return;
  46.     }
  47.     if (!(obj = get_letter_object(ch))) {
  48.         message("no such item.", 0);
  49.         return;
  50.     }
  51.     if (obj->what_is != POTION) {
  52.         message("you can't drink that", 0);
  53.         return;
  54.     }
  55.     switch(obj->which_kind) {
  56.         case INCREASE_STRENGTH:
  57.             message("you feel stronger now, what bulging muscles!",
  58.             0);
  59.             rogue.str_current++;
  60.             if (rogue.str_current > rogue.str_max) {
  61.                 rogue.str_max = rogue.str_current;
  62.             }
  63.             break;
  64.         case RESTORE_STRENGTH:
  65.             rogue.str_current = rogue.str_max;
  66.             message("this tastes great, you feel warm all over", 0);
  67.             break;
  68.         case HEALING:
  69.             message("you begin to feel better", 0);
  70.             potion_heal(0);
  71.             break;
  72.         case EXTRA_HEALING:
  73.             message("you begin to feel much better", 0);
  74.             potion_heal(1);
  75.             break;
  76.         case POISON:
  77.             if (!sustain_strength) {
  78.                 rogue.str_current -= get_rand(1, 3);
  79.                 if (rogue.str_current < 1) {
  80.                     rogue.str_current = 1;
  81.                 }
  82.             }
  83.             message("you feel very sick now", 0);
  84.             if (halluc) {
  85.                 unhallucinate();
  86.             }
  87.             break;
  88.         case RAISE_LEVEL:
  89.             rogue.exp_points = level_points[rogue.exp - 1];
  90.             add_exp(1, 1);
  91.             break;
  92.         case BLINDNESS:
  93.             go_blind();
  94.             break;
  95.         case HALLUCINATION:
  96.             message("oh wow, everything seems so cosmic", 0);
  97.             halluc += get_rand(500, 800);
  98.             break;
  99.         case DETECT_MONSTER:
  100.             show_monsters();
  101.             if (!(level_monsters.next_monster)) {
  102.                 message(strange_feeling, 0);
  103.             }
  104.             break;
  105.         case DETECT_OBJECTS:
  106.             if (level_objects.next_object) {
  107.                 if (!blind) {
  108.                     show_objects();
  109.                 }
  110.             } else {
  111.                 message(strange_feeling, 0);
  112.             }
  113.             break;
  114.         case CONFUSION:
  115.             message((halluc ? "what a trippy feeling" :
  116.             "you feel confused"), 0);
  117.             confuse();
  118.             break;
  119.         case LEVITATION:
  120.             message("you start to float in the air", 0);
  121.             levitate += get_rand(15, 30);
  122.             being_held = bear_trap = 0;
  123.             break;
  124.         case HASTE_SELF:
  125.             message("you feel yourself moving much faster", 0);
  126.             haste_self += get_rand(11, 21);
  127.             if (!(haste_self % 2)) {
  128.                 haste_self++;
  129.             }
  130.             break;
  131.         case SEE_INVISIBLE:
  132.             sprintf(buf, "hmm, this potion tastes like %sjuice", fruit);
  133.             message(buf, 0);
  134.             if (blind) {
  135.                 unblind();
  136.             }
  137.             see_invisible = 1;
  138.             relight();
  139.             break;
  140.     }
  141.     print_stats((STAT_STRENGTH | STAT_HP));
  142.     if (id_potions[obj->which_kind].id_status != CALLED) {
  143.         id_potions[obj->which_kind].id_status = IDENTIFIED;
  144.     }
  145.     vanish(obj, 1, &rogue.pack);
  146. }
  147.  
  148. read_scroll()
  149. {
  150.     short ch;
  151.     object *obj;
  152.     char msg[DCOLS];
  153.  
  154.     ch = pack_letter("read what?", SCROLL);
  155.  
  156.     if (ch == CANCEL) {
  157.         return;
  158.     }
  159.     if (!(obj = get_letter_object(ch))) {
  160.         message("no such item.", 0);
  161.         return;
  162.     }
  163.     if (obj->what_is != SCROLL) {
  164.         message("you can't read that", 0);
  165.         return;
  166.     }
  167.     switch(obj->which_kind) {
  168.         case SCARE_MONSTER:
  169.             message("you hear a maniacal laughter in the distance",
  170.             0);
  171.             break;
  172.         case HOLD_MONSTER:
  173.             hold_monster();
  174.             break;
  175.         case ENCH_WEAPON:
  176.             if (rogue.weapon) {
  177.                 if (rogue.weapon->what_is == WEAPON) {
  178.                     sprintf(msg, "your %sglow%s %sfor a moment",
  179.                     name_of(rogue.weapon),
  180.                     ((rogue.weapon->quantity <= 1) ? "s" : ""),
  181.                     get_ench_color());
  182.                     message(msg, 0);
  183.                     if (coin_toss()) {
  184.                         rogue.weapon->hit_enchant++;
  185.                     } else {
  186.                         rogue.weapon->d_enchant++;
  187.                     }
  188.                 }
  189.                 rogue.weapon->is_cursed = 0;
  190.             } else {
  191.                 message("your hands tingle", 0);
  192.             }
  193.             break;
  194.         case ENCH_ARMOR:
  195.             if (rogue.armor) {
  196.                 sprintf(msg, "your armor glows %sfor a moment",
  197.                 get_ench_color());
  198.                 message(msg, 0);
  199.                 rogue.armor->d_enchant++;
  200.                 rogue.armor->is_cursed = 0;
  201.                 print_stats(STAT_ARMOR);
  202.             } else {
  203.                 message("your skin crawls", 0);
  204.             }
  205.             break;
  206.         case IDENTIFY:
  207.             message("this is a scroll of identify", 0);
  208.             obj->identified = 1;
  209.             id_scrolls[obj->which_kind].id_status = IDENTIFIED;
  210.             idntfy();
  211.             break;
  212.         case TELEPORT:
  213.             tele();
  214.             break;
  215.         case SLEEP:
  216.             message("you fall asleep", 0);
  217.             take_a_nap();
  218.             break;
  219.         case PROTECT_ARMOR:
  220.             if (rogue.armor) {
  221.                 message( "your armor is covered by a shimmering gold shield",0);
  222.                 rogue.armor->is_protected = 1;
  223.                 rogue.armor->is_cursed = 0;
  224.             } else {
  225.                 message("your acne seems to have disappeared", 0);
  226.             }
  227.             break;
  228.         case REMOVE_CURSE:
  229.                 message((!halluc) ?
  230.                     "you feel as though someone is watching over you" :
  231.                     "you feel in touch with the universal oneness", 0);
  232.             uncurse_all();
  233.             break;
  234.         case CREATE_MONSTER:
  235.             create_monster();
  236.             break;
  237.         case AGGRAVATE_MONSTER:
  238.             aggravate();
  239.             break;
  240.         case MAGIC_MAPPING:
  241.             message("this scroll seems to have a map on it", 0);
  242.             draw_magic_map();
  243.             break;
  244.     }
  245.     if (id_scrolls[obj->which_kind].id_status != CALLED) {
  246.         id_scrolls[obj->which_kind].id_status = IDENTIFIED;
  247.     }
  248.     vanish(obj, (obj->which_kind != SLEEP), &rogue.pack);
  249. }
  250.  
  251. /* vanish() does NOT handle a quiver of weapons with more than one
  252.    arrow (or whatever) in the quiver.  It will only decrement the count.
  253. */
  254.  
  255. vanish(obj, rm, pack)
  256. object *obj;
  257. short rm;
  258. object *pack;
  259. {
  260.     if (obj->quantity > 1) {
  261.         obj->quantity--;
  262.     } else {
  263.         if (obj->in_use_flags & BEING_WIELDED) {
  264.             unwield(obj);
  265.         } else if (obj->in_use_flags & BEING_WORN) {
  266.             unwear(obj);
  267.         } else if (obj->in_use_flags & ON_EITHER_HAND) {
  268.             un_put_on(obj);
  269.         }
  270.         take_from_pack(obj, pack);
  271.         free_object(obj);
  272.     }
  273.     if (rm) {
  274.         (void) reg_move();
  275.     }
  276. }
  277.  
  278. potion_heal(extra)
  279. {
  280.     float ratio;
  281.     short add;
  282.  
  283.     rogue.hp_current += rogue.exp;
  284.  
  285.     ratio = ((float)rogue.hp_current) / rogue.hp_max;
  286.  
  287.     if (ratio >= 1.00) {
  288.         rogue.hp_max += (extra ? 2 : 1);
  289.         extra_hp += (extra ? 2 : 1);
  290.         rogue.hp_current = rogue.hp_max;
  291.     } else if (ratio >= 0.90) {
  292.         rogue.hp_max += (extra ? 1 : 0);
  293.         extra_hp += (extra ? 1 : 0);
  294.         rogue.hp_current = rogue.hp_max;
  295.     } else {
  296.         if (ratio < 0.33) {
  297.             ratio = 0.33;
  298.         }
  299.         if (extra) {
  300.             ratio += ratio;
  301.         }
  302.         add = (short)(ratio * ((float)rogue.hp_max - rogue.hp_current));
  303.         rogue.hp_current += add;
  304.         if (rogue.hp_current > rogue.hp_max) {
  305.             rogue.hp_current = rogue.hp_max;
  306.         }
  307.     }
  308.     if (blind) {
  309.         unblind();
  310.     }
  311.     if (confused && extra) {
  312.             unconfuse();
  313.     } else if (confused) {
  314.         confused = (confused / 2) + 1;
  315.     }
  316.     if (halluc && extra) {
  317.         unhallucinate();
  318.     } else if (halluc) {
  319.         halluc = (halluc / 2) + 1;
  320.     }
  321. }
  322.  
  323. idntfy()
  324. {
  325.     short ch;
  326.     object *obj;
  327.     struct id *id_table;
  328.     char desc[DCOLS];
  329. AGAIN:
  330.     ch = pack_letter("what would you like to identify?", ALL_OBJECTS);
  331.  
  332.     if (ch == CANCEL) {
  333.         return;
  334.     }
  335.     if (!(obj = get_letter_object(ch))) {
  336.         message("no such item, try again", 0);
  337.         message("", 0);
  338.         check_message();
  339.         goto AGAIN;
  340.     }
  341.     obj->identified = 1;
  342.     if (obj->what_is & (SCROLL | POTION | WEAPON | ARMOR | WAND | RING)) {
  343.         id_table = get_id_table(obj);
  344.         id_table[obj->which_kind].id_status = IDENTIFIED;
  345.     }
  346.     get_desc(obj, desc);
  347.     message(desc, 0);
  348. }
  349.  
  350. eat()
  351. {
  352.     short ch;
  353.     short moves;
  354.     object *obj;
  355.     char buf[70];
  356.  
  357.     ch = pack_letter("eat what?", FOOD);
  358.  
  359.     if (ch == CANCEL) {
  360.         return;
  361.     }
  362.     if (!(obj = get_letter_object(ch))) {
  363.         message("no such item.", 0);
  364.         return;
  365.     }
  366.     if (obj->what_is != FOOD) {
  367.         message("you can't eat that", 0);
  368.         return;
  369.     }
  370.     if ((obj->which_kind == FRUIT) || rand_percent(60)) {
  371.         moves = get_rand(900, 1100);
  372.         if (obj->which_kind == RATION) {
  373.             message("yum, that tasted good", 0);
  374.         } else {
  375.             sprintf(buf, "my, that was a yummy %s", fruit);
  376.             message(buf, 0);
  377.         }
  378.     } else {
  379.         moves = get_rand(700, 900);
  380.         message("yuk, that food tasted awful", 0);
  381.         add_exp(2, 1);
  382.     }
  383.     rogue.moves_left /= 3;
  384.     rogue.moves_left += moves;
  385.     hunger_str[0] = 0;
  386.     print_stats(STAT_HUNGER);
  387.  
  388.     vanish(obj, 1, &rogue.pack);
  389. }
  390.  
  391. hold_monster()
  392. {
  393.     short i, j;
  394.     short mcount = 0;
  395.     object *monster;
  396.     short row, col;
  397.  
  398.     for (i = -2; i <= 2; i++) {
  399.         for (j = -2; j <= 2; j++) {
  400.             row = rogue.row + i;
  401.             col = rogue.col + j;
  402.             if ((row < MIN_ROW) || (row > (DROWS-2)) || (col < 0) ||
  403.                  (col > (DCOLS-1))) {
  404.                 continue;
  405.             }
  406.             if (dungeon[row][col] & MONSTER) {
  407.                 monster = object_at(&level_monsters, row, col);
  408.                 monster->m_flags |= ASLEEP;
  409.                 monster->m_flags &= (~WAKENS);
  410.                 mcount++;
  411.             }
  412.         }
  413.     }
  414.     if (mcount == 0) {
  415.         message("you feel a strange sense of loss", 0);
  416.     } else if (mcount == 1) {
  417.         message("the monster freezes", 0);
  418.     } else {
  419.         message("the monsters around you freeze", 0);
  420.     }
  421. }
  422.  
  423. tele()
  424. {
  425.     mvaddch(rogue.row, rogue.col, get_dungeon_char(rogue.row, rogue.col));
  426.  
  427.     if (cur_room >= 0) {
  428.         darken_room(cur_room);
  429.     }
  430.     put_player(get_room_number(rogue.row, rogue.col));
  431.     being_held = 0;
  432.     bear_trap = 0;
  433. }
  434.  
  435. hallucinate()
  436. {
  437.     object *obj, *monster;
  438.     short ch;
  439.  
  440.     if (blind) return;
  441.  
  442.     obj = level_objects.next_object;
  443.  
  444.     while (obj) {
  445.         ch = mvinch(obj->row, obj->col);
  446.         if (((ch < 'A') || (ch > 'Z')) &&
  447.             ((obj->row != rogue.row) || (obj->col != rogue.col)))
  448.         if ((ch != ' ') && (ch != '.') && (ch != '#') && (ch != '+')) {
  449.             addch(gr_obj_char());
  450.         }
  451.         obj = obj->next_object;
  452.     }
  453.     monster = level_monsters.next_monster;
  454.  
  455.     while (monster) {
  456.         ch = mvinch(monster->row, monster->col);
  457.         if ((ch >= 'A') && (ch <= 'Z')) {
  458.             addch(get_rand('A', 'Z'));
  459.         }
  460.         monster = monster->next_monster;
  461.     }
  462. }
  463.  
  464. unhallucinate()
  465. {
  466.     halluc = 0;
  467.     relight();
  468.     message("everything looks SO boring now", 1);
  469. }
  470.  
  471. unblind()
  472. {
  473.     blind = 0;
  474.     message("the veil of darkness lifts", 1);
  475.     relight();
  476.     if (halluc) {
  477.         hallucinate();
  478.     }
  479.     if (detect_monster) {
  480.         show_monsters();
  481.     }
  482. }
  483.  
  484. relight()
  485. {
  486.     if (cur_room == PASSAGE) {
  487.         light_passage(rogue.row, rogue.col);
  488.     } else {
  489.         light_up_room(cur_room);
  490.     }
  491.     mvaddch(rogue.row, rogue.col, rogue.fchar);
  492. }
  493.  
  494. take_a_nap()
  495. {
  496.     short i;
  497.  
  498.     i = get_rand(2, 5);
  499.     md_sleep(1);
  500.  
  501.     while (i--) {
  502.         mv_mons();
  503.     }
  504.     md_sleep(1);
  505.     message(you_can_move_again, 0);
  506. }
  507.  
  508. go_blind()
  509. {
  510.     short i, j;
  511.  
  512.     if (!blind) {
  513.         message("a cloak of darkness falls around you", 0);
  514.     }
  515.     blind += get_rand(500, 800);
  516.  
  517.     if (detect_monster) {
  518.         object *monster;
  519.  
  520.         monster = level_monsters.next_monster;
  521.  
  522.         while (monster) {
  523.             mvaddch(monster->row, monster->col, monster->trail_char);
  524.             monster = monster->next_monster;
  525.         }
  526.     }
  527.     if (cur_room >= 0) {
  528.         for (i = rooms[cur_room].top_row + 1;
  529.              i < rooms[cur_room].bottom_row; i++) {
  530.             for (j = rooms[cur_room].left_col + 1;
  531.                  j < rooms[cur_room].right_col; j++) {
  532.                 mvaddch(i, j, ' ');
  533.             }
  534.         }
  535.     }
  536.     mvaddch(rogue.row, rogue.col, rogue.fchar);
  537. }
  538.  
  539. char *
  540. get_ench_color()
  541. {
  542.     if (halluc) {
  543.         return(id_potions[get_rand(0, POTIONS-1)].title);
  544.     }
  545.     return("blue ");
  546. }
  547.  
  548. confuse()
  549. {
  550.     confused += get_rand(12, 22);
  551. }
  552.  
  553. unconfuse()
  554. {
  555.     char msg[80];
  556.  
  557.     confused = 0;
  558.     sprintf(msg, "you feel less %s now", (halluc ? "trippy" : "confused"));
  559.     message(msg, 1);
  560. }
  561.  
  562. uncurse_all()
  563. {
  564.     object *obj;
  565.  
  566.     obj = rogue.pack.next_object;
  567.  
  568.     while (obj) {
  569.         obj->is_cursed = 0;
  570.         obj = obj->next_object;
  571.     }
  572. }
  573.